Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VRT processed dataset: unscale source raster values #11623

Merged
merged 4 commits into from
Jan 10, 2025

Conversation

dbaston
Copy link
Member

@dbaston dbaston commented Jan 9, 2025

Alternative to #11573 . Introduces an attribute scale to <Input> with default value auto. This will cause input datasets with a defined scale or offset to be unscaled to Float64 (also causing output bands to be Float64). <Input unscale="false"> prevents this and keeps the current behavior. <Input scale="true"> invokes the unscaling machinery regardless of the defined scale/offset values in the input dataset, so that the output type is always consistent.

I don't love the implementation which ends up touching VRTProcessedDataset in several places. I think a cleaner implementation could involve creating a method like GDALRasterBand* GDALRasterBand::GetUnscaled(). If the band was not scaled it could return a reference to itself; for a band with scaling it could return a a wrapper GDALScaledRasterBand with appropriate overloads of IRasterIO, GetNoDataValue, etc. This would also provide a consolidated location for an optimized (SSE?) implementation of the unscaling.

cc @jratike80

@rouault
Copy link
Member

rouault commented Jan 9, 2025

which ends up touching VRTProcessedDataset in several places

indeed. I thought you were going to silently add the unscale processing functions as a first step. Wouldn't that simplify things ?

I think a cleaner implementation could involve creating a method like GDALRasterBand* GDALRasterBand::GetUnscaled()

or just use the dataset returned by GDALTranslate("", hSrcDS, options = "-f VRT -unscale") which will handle all details, including reading from overviews.

@dbaston
Copy link
Member Author

dbaston commented Jan 9, 2025

Wouldn't that simplify things ?

In some ways. But there's still a problem where the BandScaleOffset algorithm can't set the scale/offset properties on the output, so you would get different behavior if you include it as an explicit processing step vs implicitly via <Input unscale="true">. This seems like it would be confusing.

or just use the dataset returned by GDALTranslate("", hSrcDS, options = "-f VRT -unscale")

I'll give this a try.

@rouault
Copy link
Member

rouault commented Jan 10, 2025

macos_build failure unrelated, and should be solved by rebasing on top of latest master

@dbaston dbaston force-pushed the processed-vrt-unscale-2 branch from 2048e21 to d514839 Compare January 10, 2025 00:59
@rouault
Copy link
Member

rouault commented Jan 10, 2025

@dbaston Please also edit frmts/vrt/data/gdalvrt.xsd to add the new attribute

@rouault rouault added this to the 3.11.0 milestone Jan 10, 2025
@rouault rouault merged commit ee04fce into OSGeo:master Jan 10, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants